package com.ruoyi.wechat.api;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wechat.domain.WxActivity;
import com.ruoyi.wechat.domain.WxScenicSpots;
import com.ruoyi.wechat.service.IWxActivityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 营地活动管理
 */
@RestController
@RequestMapping("/wechat/activity")
public class WxActivityController extends BaseController {

    @Autowired
    private IWxActivityService  wxActivityService;

    /**
     * 根据营地Id获取该营地下的活动列表
     * @param campId
     * @return
     */
    @GetMapping("/getInfoByCampId/{campId}")
    public AjaxResult getInfoByCampId(@PathVariable("campId") String campId) {
        if (campId == null) {
            return error("营地Id不能为空");
        }
        List<WxActivity> list = wxActivityService.getInfoByCampId(campId);
        return success(list);
    }

    /**
     * 根据活动Id查询详细信息
     * @param activityId
     * @return
     */
    @GetMapping("/getInfoByActivityId/{activityId}")
    public AjaxResult getInfoByScenicId(@PathVariable("activityId") String activityId) {
        if (activityId == null) {
            return error("活动Id不能为空");
        }
        WxActivity wxActivity = wxActivityService.getInfo(activityId);
        return success(wxActivity);
    }

    /**
     * 添加活动并提交审批
     * @param wxActivity
     * @return
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody WxActivity wxActivity){
        if (wxActivity == null) {
            return error("数据不能为空");
        }
        if (wxActivity.getCampId() == null) {
            return error("营地Id不能为空");
        }
        if (wxActivity.getActivityName() == null) {
            return error("活动名称不能为空");
        }
        if (wxActivity.getOriginalPrice() == null) {
            return error("原价不能为空");
        }
        return toAjax(wxActivityService.insertWxActivity(wxActivity));
    }


    /**
     * 修改活动并提交审批
     * @param wxActivity
     * @return
     */
    @PutMapping("/update")
    public AjaxResult update(@RequestBody WxActivity wxActivity) {
        if (wxActivity == null) {
            return error("数据不能为空");
        }
        if (wxActivity.getActivityId() == null) {
            return error("营地活动Id不能为空");
        }
        if (wxActivity.getCampId() == null) {
            return error("营地Id不能为空");
        }
        if (wxActivity.getActivityName() == null) {
            return error("活动名称不能为空");
        }
        if (wxActivity.getOriginalPrice() == null) {
            return error("原价不能为空");
        }
        return toAjax(wxActivityService.updateWxActivity(wxActivity));
    }

    /**
     * 根据活动Id完成删除
     * @param activityId
     * @return
     */
    @DeleteMapping("/delete/{activityId}")
    public AjaxResult delete(@PathVariable("activityId") String activityId){
        if (activityId == null) {
            return error("活动Id不能为空");
        }
        return toAjax(wxActivityService.deleteWxActivityByActivityId(activityId));
    }
}
